<?php
/*
	本插件：$this->model('agent')->方法名();
	其他地方调用：model('jy_agentmcp/agent')->方法名();
*/
namespace jy_agentmcp;
defined('BY_JYA') or exit('error');
class agent extends \plugin{
	public function addusergoods($postdata=array(),$mid=0){
		$mid=$mid?:$_SESSION['uid'];
		$this->model('member')->checkvip($mid);
		$data=array(
			'title'=>trim($postdata['title']),
			'mcpurl'=>trim($postdata['mcpurl']),
			'status'=>$postdata['status']?:0,
		);
		$id=intval($postdata['id']);
		if($id){
			pdo_update('jy_agentmcp_usergoods',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}else{
			$data['uniacid']=$_SESSION['uniacid'];
			$data['alias']=$postdata['alias'];
			$data['code']=$postdata['code'];
			$data['deviceid']=$postdata['deviceid'];
			$data['gu_v']=$postdata['gu_v'];
			$data['macsn']=$postdata['macsn'];
			$data['agentid']=$postdata['agentid'];
			$data['agentapiid']=$postdata['agentapiid'];
			$data['mid']=$mid;
			$data['createtime']=TIMESTAMP;
			pdo_insert('jy_agentmcp_usergoods',$data);
			$data['id']=pdo_insertid();
			$id=$data['id'];
		}
		if($postdata['mcpurl']){
			//$usergoods=pdo_get('jy_agentmcp_usergoods',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			//$this->model('mcp')->bindMcpEndpoint($usergoods);
		}
		return $id;
	}
}
?>